
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>账户管理</title>
    {include file='header'}
</head>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a>后台账户</a>
        </span>
        <div style="float: right;">            
            <a href="javascript:;" onclick="xadmin.open('添加用户','{:url('modify')}')"><button class="layui-btn"><i class="layui-icon">&#xe61f;</i>添加</button></a>
            <!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>-->
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh-1"></i></a>
        </div>
    </div>
    <div class="x-body">
        <div class="layui-row">
        <form class="layui-form">
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="登录名" name="keyword">
                </div>
                <div class="layui-input-inline">
                    <select name="danwei_id">
                        <option value="">单位</option>{foreach $danwei as $v}
                        <option value="{$v.id}">{$v.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-input-inline layui-show-xs-block">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach">搜索</button>
                </div>
            </form>
    </div>
        <table class="layui-table layui-form">
            <thead>
                <tr>
                    <th style="width: 25px;">
                        <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                    </th>
                    <th>用户名</th>
                    <th>姓名</th>
                    <th>单位</th>
                    <th>角色</th>
                    <th>登录次数</th>
                    <th>登录时间</th>
                    <th style="width: 80px; text-align: center;">状态</th>
                    <th style="width:120px; text-align: center;">操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach $data_list as $vo}
                <tr>
                    <th style="width: 25px;">
                        <input type="checkbox" name="id" value="{$vo.id}"   lay-skin="primary">
                    </td>
                     <td>{$vo.username}</td>
                    <td>{$vo.name}</td>
                    <td>{if !empty($vo.danwei)}{$vo.danwei.name}{/if}</td>
                    <td>{$vo.role_name}</td>
                    <td>{$vo.login_total}</td>
                    <td>{$vo.login_time}</td>
                    <td style="text-align: center;">{if $vo.status==0}无效{else}有效{/if}</td>
                    <td style="text-align: center;">
                        <a class="layui-btn layui-btn-xs" href="javascript:;" onclick="xadmin.open('编辑用户','{:url('modify',['id'=>$vo.id])}')">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove('{$vo.id}')">删 除</a>
                    </td>
                </tr>{/foreach}             
            </tbody>
        </table>
        {$page|raw}
    </div>
    <script>
    function setChild()
    {
        
    }
    function set_status(id,status){
        $.post("{:url('status')}",{id:id,status:status},function(res){
        if(res.code==1)
        {
          layer.msg('操作成功',{icon:1,time:1000},function(){
            location.reload();
          })
        }
        else
        {
          layer.msg('操作失败');
        }
      },'json');
    }
    function remove(id)
    {
        if(confirm('确定要删除数据吗?'))
        {
        $.post("{:url('remove')}",{id:id},function(res){
            if(res.code==1)
            {
            layer.msg('删除成功',{icon:1,time:1000},function(){
                var index = parent.layer.getFrameIndex(window.name);
                    window.parent.location.reload();
                    parent.layer.close(index);
            })
            }
            else
            {
            layer.msg('操作失败');
            }
        })
        }
    }
    /*用户-批量删除*/
    function delAll(argument) {
        var ids = [];
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
        if(ids.length==0)
        {
            layer.msg("请选择项目")
            return;
        }
        console.log('ids:'+ids)
        //return;
        layer.confirm('确认要删除所选吗？', function (index) {
            layer.close(index);
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type: "POST",
                url: "{:url('remove')}",
                data: { "id": ids },
                datatype: "json",
                success: function (res, textStatus) {
                    console.log(res)
                    if (res.code == 1) {
                        layer.msg(res.msg, { icon: 1, time: 1000 },function(){
                            location.reload()
                        });
                        
                    }
                    else {
                        layer.alert(res.msg);
                        return false;
                    }
                },
                error: function (e) {
                    layer.alert('系统出现错误,请检查系统！', { icon: 2 });//0感叹号  1打勾  2打叉  3问号  4锁头  5难过  6笑脸
                    return false;
                }
            });
        });
    }
    layui.use(['laydate','form'], function(){        
        var  form = layui.form;
        form.on('checkbox(checkall)', function(data){
          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 
    })
    </script>
</body>
</html>